#include "ActivationLayer.h"
#include "ActivationNeuron.h"
using namespace NeuralPlusPlus::Core;
using namespace NeuralPlusPlus::Core::Backpropagation;

NeuralPlusPlus::Core::Backpropagation::ActivationLayer::ActivationLayer( int neuronCount ) : Layer(neuronCount)
	{
	this->UseFixedBiasValues = false;
	for (int i = 0; i < neuronCount; i++)
		{
		Neurons[i] = (INeuron*)new ActivationNeuron(this);
		}
	}

void NeuralPlusPlus::Core::Backpropagation::ActivationLayer::Initialize()
	{
	if (Initializer != NULL)
		{
		Initializer->Initialize(this);
		}
	}

double NeuralPlusPlus::Core::Backpropagation::ActivationLayer::SetErrors( double* expectedOutput )
	{
	double meanSquaredError = 0.0;
	for (int i = 0; i < NeuronsLength; i++)
		{
		ActivationNeuron* neuron = (ActivationNeuron*)Neurons[i]; 
		neuron->Error = expectedOutput[i] - neuron->Output;
		meanSquaredError += neuron->Error * neuron->Error;
		}
	return meanSquaredError;
	}

void NeuralPlusPlus::Core::Backpropagation::ActivationLayer::EvaluateErrors()
	{
	for (int i = 0; i < NeuronsLength; i++)
		{
		((ActivationNeuron*)Neurons[i])->EvaluateError();
		}
	}